<!-- <!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2025-09-11 08:37:19
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2025-09-17 17:15:32
 * @FilePath: \23WRX\city\src\pages\components\Left1.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <Title :title="title"></Title>
        <div ref="bottom2" style="height: 150px ;padding: 30px;"></div>
    </div>
</template>
<script>
import Title from './Title.vue';
import { Rose } from '@antv/g2plot';
import { get } from '@/utils/request';
import moment from 'moment';
import { mapState } from 'vuex';
export default {
    data() {
        return {
            title: '风速',
             params: {
                page: 1,
                pageSize: 200
            },
            fData:[],
            rose:null
        }
    },
    computed: {
        ...mapState(['ed'])
    },
     watch: {
        ed: {
            handler(n, o) {
                // 根据设备信息重新查询数据 重新渲染图表 
                this.params.engineer_id = n.engineer_id;
                this.params.device_id = n.device_id;
                this.getFData();
                // 根据最新获取的数据重新渲染图表 
                this.rose.changeData(this.fData);
            },
            // 深度监听 
            deep: true
        }
    },
    methods: {
        loadRose() {
            this.rose = new Rose(this.$refs.bottom2, {
                data:this.fData,
                xField: 'insert_time',
                yField: 'noise',
                autoFit: true,
                seriesField: null,
                radius: 1,
                color:'blue',
                xAxis:{
                    label:{
                        style:{
                            fill:'red',
                            fontSize:10
                        }
                    }
                },
                label: {
                    style: {
                        fill: 'red',
                        fontSize:0
                    }
                },
                legend: {
                    position: 'bottom',
                },
            });

            this.rose.render();

        },
        async getFData(){
            let res = await new get('/dashboard/pageQueryData',this.params);
            let temp = [];
            // 将后端获取的数据设置给tempData 
            res.data.list.forEach((item, index, arr) => {
                // item表示数组每一项 
                item.insert_time = moment(item.insert_time).format("HH:mm");
                // 由于查询数据密度密集 需要将数据处理 每隔10条数据取一条数据 
                if (index % 10 == 0) {
                    temp.push(arr[index])
                }
            });
            this.fData = temp;
        }
    },
    async mounted() {
        await this.getFData();
        this.loadRose();
    }
}
</script>
<style lang="less" scoped></style>